package com.bw.user.mvvm.viewmodel;

import android.text.TextUtils;

import androidx.databinding.ObservableField;

import com.blankj.utilcode.util.ToastUtils;
import com.bw.mvvm_common.entity.BaseEntity;
import com.bw.mvvm_common.mvvm.viewmodel.BaseViewModel;
import com.bw.user.mvvm.model.RegisterModel;
import com.bw.user.mvvm.model.entity.RegisterEntity;

import java.util.HashMap;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public
/**
 * @author Lishaohe
 * @description:
 * @date :2021/10/19 0019 下午 5:59
 *
 */
class RegisterViewModel extends BaseViewModel<RegisterModel> {

    public ObservableField<String> phone = new ObservableField<>();
    public ObservableField<String> timeStr = new ObservableField<>();
    public ObservableField<String> verify1 = new ObservableField<>();
    public ObservableField<String> pwd = new ObservableField<>();
    public ObservableField<String> confirmpwd = new ObservableField<>();

    @Override
    public void onCreate() {
        super.onCreate();

    }

    @Override
    protected void result(BaseEntity entity) {
        RegisterEntity registerEntity = (RegisterEntity) entity;

        if (registerEntity.getMessage().equals("注册成功")){
            ToastUtils.showLong("注册成功");
            finishPage();
        }else {
            ToastUtils.showLong("sb");
        }
    }
    //验证码按钮
    public void verify(){

    }
    //返回按钮
    public void finish(){
        finishPage();
    }
    //注册按钮
    public void confirm(){
        if (TextUtils.isEmpty(phone.get())||TextUtils.isEmpty(pwd.get())||TextUtils.isEmpty(verify1.get())){
            ToastUtils.showLong("空");
        }else {
            HashMap<String,Object> map = new HashMap<>();
            map.put("mobile",phone.get());
            map.put("pwd",pwd.get());
            map.put("verifyCode",verify1.get());
            m.requsetReg(map)
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribeOn(Schedulers.io())
                    .subscribe(this);
        }
    }
}
